package com.example.springredirectafterlogin.controller;

import com.example.springredirectafterlogin.entity.Foo;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping(value = "/auth/foo")
public class FooController {

    @GetMapping(value = "/{id}",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Foo> findById(@PathVariable("id") final Integer id){
        Foo foo = new Foo(RandomStringUtils.randomAlphabetic(6));
        return new ResponseEntity<>(foo, HttpStatus.OK);
    }

    @GetMapping(value = "",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<Foo>> findAll(){
        return new ResponseEntity<>(Arrays.asList(new Foo(RandomStringUtils.randomAlphabetic(6))),HttpStatus.OK);
    }

    @PostMapping(value = "",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.CREATED)
    public Foo create(@RequestBody final Foo foo){
        return foo;
    }
}
